import java.util.Scanner;

public class StrSub {
    //查找两个字符串a,b中的最长公共子串
    private static String getMaxSub(String str1,String str2){
        char[] ch1=str1.toCharArray();
        char[] ch2=str2.toCharArray();
        int maxLine=0;
        int[][] maxSubLine=new int[ch1.length+1][ch2.length+1];
        int start=0;
        for (int i = 1; i <ch1.length+1 ; i++) {
            for (int j = 1; j <ch2.length+1 ; j++) {
                if(ch1[i-1]==ch2[j-1]){
                    maxSubLine[i][j]=maxSubLine[i-1][j-1]+1;//a字符串i位置与b字符串j位置的字符相同,相同子字符串长度+1
                    if(maxLine<maxSubLine[i][j]){
                        maxLine=maxSubLine[i][j];
                        start=i-maxLine;
                    }
                }
            }
        }
        return str1.substring(start,start+maxLine);
    }
    public static void main42(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()){
            String str1=scanner.nextLine();
            String str2=scanner.nextLine();
            if(str1.length()<str2.length()){
                System.out.println(getMaxSub(str1,str2));
            }else {
                System.out.println(getMaxSub(str2,str1));

            }
        }
    }
    private static int getMaxLine(String str1,String str2){
        char[] ch1=str1.toCharArray();
        char[] ch2=str2.toCharArray();
        int maxLine=0;
        int[][] maxSubLine=new int[ch1.length+1][ch2.length+1];
        for (int i = 1; i <ch1.length+1 ; i++) {
            for (int j = 1; j <ch2.length+1 ; j++) {
                if(ch1[i-1]==ch2[j-1]){
                    maxSubLine[i][j]=maxSubLine[i-1][j-1]+1;
                    if(maxLine<maxSubLine[i][j]){
                        maxLine=maxSubLine[i][j];
                    }
                }
            }
        }
        return maxLine;
    }
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        String str1=scan.nextLine();
        String str2=scan.nextLine();
        if(str1.length()<str2.length()){
            System.out.println(getMaxLine(str1,str2));
        }else {
            System.out.println(getMaxLine(str2,str1));
        }
    }
}
